window.onload=function (){
    var result;
    axios({
        method: 'get',
        url: '/ReservationController/selectRoomIdNotNull'
    }).then(function (resp) {
        if (resp){
            result=resp.data.data;
            var tbody=document.getElementById("tbody");
            //循环添加节点，动态生成
            for (var i=0;i<result.length;i++){
                //设置index属性，循环绑定
                var td1=document.createElement("td");
                var td2=document.createElement("td");
                var td3=document.createElement("td");
                var td4=document.createElement("td");
                var td5=document.createElement("td");
                var td6=document.createElement("td");
                var td7=document.createElement("td");
                td1.innerHTML=i+1;
                td2.innerHTML=result[i].id;
                td3.innerHTML=result[i].roomID;
                td4.innerHTML=result[i].arriveTime;
                td5.innerHTML=result[i].predetermineDay;
                td6.innerHTML=result[i].payWayName;
                var inputIntd=document.createElement("input");
                inputIntd.type='button';
                inputIntd.value='删除';
                inputIntd.name='checkItem';
                //添加属性，循环绑定
                inputIntd.addindex=i;
                td7.appendChild(inputIntd);
                var tr=document.createElement('tr');
                tr.appendChild(td1);
                tr.appendChild(td2);
                tr.appendChild(td3);
                tr.appendChild(td4);
                tr.appendChild(td5);
                tr.appendChild(td6);
                tr.appendChild(td7);
                tbody.appendChild(tr);
                //给每一个删除按钮绑定时间
                //console.log(temp.addindex);
                inputIntd.onclick=function (){
                    var ind=this.addindex;
                    //console.log(this.addindex);
                    axios({
                        method: 'put',
                        url: '/RoomController/updateroomStatethree/'+result[ind].roomID
                    }).then(function (resp) {
                        //console.log(this.addindex);
                        axios({
                            method: 'delete',
                            url: '/ReservationController/deleteById/'+result[ind].id
                        }).then(function (resp) {
                        });
                        alert('已完成对房间id为'+result[ind].roomID+'的取消');
                        window.location.reload();
                    });

                }

            }
        }
        else {

        }
    });

    //输入预定id和登记时间
    document.getElementById("deal").onclick=function (){

        var ydid=document.getElementById("ydid").value;
        var rtime=document.getElementById("rtime").value;

        axios({
            method: 'put',
            url: '/ReservationController/handleStayRegister/'+ydid+'/'+rtime
        }).then(function (resp) {
            if (resp){
                alert('安排成功！');
            }
            else {
                alert('安排失败！');
            }
            window.location.reload();
        });

    }

}